package com.colabo.j2ee.web.oaf.monitorperspective.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import com.colabo.j2ee.web.core.context.ContextUtil;
import com.colabo.j2ee.web.core.exception.ServiceException;
import com.colabo.j2ee.web.core.vo.RecordObject;
import com.colabo.j2ee.web.oaf.monitorperspective.IScheduledTaskConfigService;
import com.colabo.j2ee.web.oaf.vo.IPScheduledTaskVO;


public class ScheduledTaskViewAction {
	
	IScheduledTaskConfigService stcService = (IScheduledTaskConfigService) ContextUtil.getBean(IScheduledTaskConfigService.BEAN_ID);
	public String loadScheduledTasks() throws Exception{
			List<IPScheduledTaskVO> resultvalue = stcService.findAllScheduledTasks();
			for (IPScheduledTaskVO item : resultvalue) {
				if (item.getStatus()!= null && item.getStatus().equals("1")){
					item.setStatus("true");
				} else {
					item.setStatus("false");
				}
			}
			JSONArray json = JSONArray.fromObject(resultvalue);
			String ret = json.toString();
			return ret;
	}
	
	public String loadScheduledTaskDetails(String pk) throws ServiceException {
		RecordObject vo = stcService.findByPK(pk);
		if (vo != null) {
			IPScheduledTaskVO stVO = (IPScheduledTaskVO) vo;
			List result = new ArrayList();
			Map item = new HashMap();
			item.put("itemName", "任务编码");
			item.put("itemValue", stVO.getTaskCode());
			result.add(item);
			item = new HashMap();
			item.put("itemName", "任务名称");
			item.put("itemValue", stVO.getTaskName());
			result.add(item);
			item = new HashMap();
			item.put("itemName", "任务说明");
			item.put("itemValue", stVO.getRemark());
			result.add(item);
			item = new HashMap();
			item.put("itemName", "业务逻辑类");
			item.put("itemValue", stVO.getTaskClass());
			result.add(item);
			item = new HashMap();
			item.put("itemName", "任务状态");
			item.put("itemValue", stVO.getStatus());
			result.add(item);
			item = new HashMap();
			item.put("itemName", "机器名称");
			item.put("itemValue", stVO.getHostName());
			result.add(item);
			item = new HashMap();
			item.put("itemName", "表达式");
			item.put("itemValue", stVO.getTaskConf());
			result.add(item);
			
			return JSONArray.fromObject(result).toString();
		} else {
			return "";
		}
	}
	
	public String loadSecurityStrategyMatrixDetails() throws ServiceException {
		return "";
	}
}
